from django.db import models
from apps.coupons.models import Coupon
from apps.member.models import Member


# Create your models here.

class MemberCoupons(models.Model):
    DEFAULT = 0
    USED = 1
    EXPIRED = 2
    STATUS_CHOICES = (
        (DEFAULT, '未使用'),
        (USED, '已使用'),
        (EXPIRED, '已过期'),
    )
    member = models.ForeignKey(Member, verbose_name='会员', editable=False, on_delete=models.PROTECT)
    coupon = models.ForeignKey(Coupon, verbose_name='优惠券', editable=False, on_delete=models.PROTECT)
    status = models.PositiveSmallIntegerField(choices=STATUS_CHOICES, verbose_name='状态', default=DEFAULT)
    create_time = models.DateTimeField(verbose_name='领取时间', auto_now_add=True)
    used_time = models.DateTimeField(verbose_name="使用时间", null=True)

    class Meta:
        db_table = 'member_coupon'
        verbose_name = '会员优惠券'
        ordering = ['-id', ]
